/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
define(["ojs/ojcore","jquery"],function(a,g){a.pf=function(a,c,d){d=d||{};this.i=c;this.ov=g(a)[0];this.Ly=d.fetchSize;this.Ly=0<this.Ly?this.Ly:25;this.sz=d.maxCount;this.sz=0<this.sz?this.sz:500;this.Zo=0;this.Wda=d.success;this.Cta=d.error;this.gw();this.pv=d.fetchTrigger;if(null==this.pv||isNaN(this.pv))this.pv=0;this.Yya=this.ov.scrollTop;g(this.QJ()).on("scroll.domscroller",function(){var a=this.ov,b=this.Nva(a),a=a.scrollHeight-a.clientHeight;0<a&&this.EU(b,a)}.bind(this))};a.pf.prototype.QJ=
function(){return this.ov==document.body||this.ov==document.documentElement?window:this.ov};a.pf.DGa=function(a,c){for(var d=0,e=c;e&&e!=a&&g.contains(a,e);)d+=e.offsetTop,e=e.offsetParent;return d};a.pf.prototype.Nva=function(a){var c=this.pv;return a==document.documentElement&&(void 0===this.Eea&&(this.Eea=this.Yya==a.scrollTop?!0:!1),this.Eea)?c+document.body.scrollTop:c+a.scrollTop};a.pf.prototype.destroy=function(){this.gp();g(this.QJ()).off("scroll.domscroller")};a.b.g("DomScroller.prototype.destroy",
{destroy:a.pf.prototype.destroy});a.pf.prototype.checkViewport=function(){return 0<this.ov.clientHeight&&!this.Vqa()?this.Y6():Promise.resolve(null)};a.b.g("DomScroller.prototype.checkViewport",{checkViewport:a.pf.prototype.checkViewport});a.pf.prototype.EU=function(a,c){if(1>=c-a&&!this.XC){var d=this;this.Y6().then(function(a){null!=d.Wda&&d.Wda(a)},this.Cta)}};a.pf.prototype.Vqa=function(){var a=this.ov;return a.scrollHeight>a.clientHeight+this.pv?!0:!1};a.pf.prototype.Y6=function(){if(this.XC)return this.XC;
var a=this.sz-this.Zo;if(0<a){var c=this.Ly,d=this;a<this.Ly&&(c=a);var e=this.Ota({pageSize:c});return this.XC=new Promise(function(c){e.then(function(e){d.XC=null;null!=e&&0<e.data.length&&(d.Zo=e.data.length+e.startIndex,a<d.Ly&&(e.maxCount=d.sz,e.maxCountLimit=!0));c(e)})})}return Promise.resolve({maxCount:this.sz,maxCountLimit:!0})};a.pf.prototype.Ota=function(a){a=a||{};var c=a.pageSize;this.Wi=this.Wi?this.Wi+c:c;if(-1==this.i.totalSize()||!this.cf()||this.cf()&&this.i.totalSize()>this.Wi){var d=
this;return new Promise(function(a,b){d.i.fetch({startIndex:d.Wi,pageSize:c}).then(function(b){a(b)},function(){b(null)})})}return Promise.resolve()};a.pf.prototype.Ps=function(){this.Wi=null;this.Zo=0};a.pf.prototype.Ewa=function(a){this.Wi=a.startIndex;0<a.data.length&&(this.Zo=a.data.length+this.Wi)};a.pf.prototype.s9=function(b){return function(c){c=c||{};c=c.indexes;var d,e=c.length;for(d=0;d<e;d++){var f=c[d];void 0!==f&&0<this.Zo&&f<=this.Zo&&(b==a.W.O.ADD?this.Zo+=1:b==a.W.O.REMOVE&&(this.Zo-=
1))}}};a.pf.prototype.cf=function(){var a=this.i;return null!=a&&"actual"==a.totalSizeConfidence()?!0:!1};a.pf.prototype.gw=function(){var b=this.i;if(null!=b){this.gp();this.vb=[];this.vb.push({eventType:a.W.O.SORT,eventHandler:this.Ps.bind(this)});this.vb.push({eventType:a.W.O.REFRESH,eventHandler:this.Ps.bind(this)});this.vb.push({eventType:a.W.O.RESET,eventHandler:this.Ps.bind(this)});this.vb.push({eventType:a.W.O.SYNC,eventHandler:this.Ewa.bind(this)});this.vb.push({eventType:a.W.O.ADD,eventHandler:this.s9(a.W.O.ADD).bind(this)});
this.vb.push({eventType:a.W.O.REMOVE,eventHandler:this.s9(a.W.O.REMOVE).bind(this)});var c,d;for(c=0;c<this.vb.length;c++)(d=b.on(this.vb[c].eventType,this.vb[c].eventHandler))&&(this.vb[c].eventHandler=d)}};a.pf.prototype.gp=function(){var a=this.i;if(null!=this.vb&&null!=a){var c;for(c=0;c<this.vb.length;c++)a.off(this.vb[c].eventType,this.vb[c].eventHandler)}}});